//
//  FeedbackViewController.m
//  JunZeWristband
//
//  Created by Kendama on 2017/8/17.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "FeedbackViewController.h"
#import "FIDPlaceholderTextView.h"
#import "FeedBackApi.h"
//#import "PublicFeedbackApi.h"
#import "FeedBackApi.h"
@interface FeedbackViewController ()

@property (strong, nonatomic)  FIDPlaceholderTextView *suggestTextView;
@property(nonatomic,strong) UITextField *nameTextField;
@property(nonatomic,strong) UIButton *commitButton;

@end

@implementation FeedbackViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)dealloc
{
    
}

- (void)refreshBaseControlValue
{
    
}

#pragma mark - 点击事件
- (void)didClickCommitButton
{
    [self.view endEditing:YES];
    
    if (self.suggestTextView.text.length == 0 ) {
        [SVProgressHUD showInfoWithStatus:@"反馈内容不能为空"];
        return;
    }
    
    if ([self.suggestTextView.text isEqualToString:@"感谢您反馈宝贵的意见"]) {
        [SVProgressHUD showInfoWithStatus:@"反馈内容不能为空"];
        return;
    }
    
    if ([NSString isContainsTwoEmoji:self.suggestTextView.text] ) {
        [SVProgressHUD showInfoWithStatus:@"意见不能使用表情"];
        return;
    }
    
    NSString *feedback = [self.suggestTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    FeedBackApi *api = [[FeedBackApi alloc]initWith:@{@"content":feedback,@"type_id":TYPEID}];
    
    [api dtDefaultInterceptStartYTKRequestCompletionBlockWithSuccess:^(YTKBaseRequest * _Nonnull request) {
        [SVProgressHUD showInfoWithStatus:@"感谢您的反馈！"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.navigationController popViewControllerAnimated:YES];
        });
    } failure:nil];

}

#pragma mark - 事件处理

#pragma mark - 代理


#pragma mark - 通知处理

#pragma mark - 初始化
- (void)setNavigationStyle
{
    [self setNavigationBarTitle:@"用户反馈"];
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.view;
    [self.suggestTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView).with.offset(px1920Height(286));
        make.left.mas_equalTo(superView).with.offset(px1080Width(40));
        make.right.mas_equalTo(superView).with.offset(-px1080Width(40));
        make.height.mas_equalTo(px1920Height(500));
    }];
    
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.suggestTextView.mas_bottom).with.offset(px1920Height(150));
        make.left.mas_equalTo(superView).with.offset(px1080Width(40));
        make.right.mas_equalTo(superView).with.offset(-px1080Width(40));
        make.height.mas_equalTo(px1920Height(136));
    }];
}

- (FIDPlaceholderTextView *)suggestTextView
{
    if(!_suggestTextView)
    {
        UIView *superView = self.view;
        _suggestTextView = [[FIDPlaceholderTextView alloc]init];
        _suggestTextView.font = [UIFont systemFontOfSize:14];
        [superView addSubview:_suggestTextView];
        _suggestTextView.layer.cornerRadius = 5;
        _suggestTextView.layer.borderColor = rgba(48,70,118,1).CGColor;
        _suggestTextView.layer.borderWidth = 1;
        _suggestTextView.backgroundColor = [UIColor clearColor];
    }
    return _suggestTextView;
}





- (UIButton *)commitButton
{
    if(!_commitButton)
    {
        UIView *superView = self.view;
        _commitButton = [[UIButton alloc]init];
        [superView addSubview:_commitButton];
        [_commitButton setTitle:@"提交" forState:UIControlStateNormal];
        [_commitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_commitButton.titleLabel setFont:fontCommonSize];
        [_commitButton setBackgroundColor:rgba(0,159,236,1)];
        _commitButton.layer.cornerRadius = 5;
        [_commitButton addTarget:self action:@selector(didClickCommitButton) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _commitButton;
}


@end
